package com.my.coolq.strategy.request.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.my.api.response.group.AddGroupResponse;
import com.my.biz.service.IGroupInfoService;
import com.my.coolq.strategy.ReceiveMessagesHandleStrategy;
import com.my.coolq.strategy.request.model.AddGroupRequest;
import com.my.util.MapUtils;
/**
 * 加群请求／邀请
 * @author ch
 *
 */
@Component
public class AddGroupRequestHandleStrategy implements ReceiveMessagesHandleStrategy{
	
	private static final Logger LOGGER = LoggerFactory.getLogger(AddGroupRequestHandleStrategy.class);

	private static final String REQUEST_TYPE="request_group";
		
	private static final String INVITE="invite";
	
	@Autowired
	private IGroupInfoService groupInfoService;
	
	@Override
	public String getPostType() {
		return REQUEST_TYPE;
	}

	@Override
	public Object handle(Map<String, Object> params) {
		try {
			
			AddGroupRequest req = MapUtils.toObject(AddGroupRequest.class, params);
			LOGGER.info("group request={}",req);
			if(INVITE.equals(req.getSub_type())  && groupInfoService.isExists(req.getGroup_id())){
				groupInfoService.inviteBotAddGroup(req.getUser_id(), req.getGroup_id());
				//groupInfoService.addGroupByAddGroupRequest(req);
			}	
		} 
		catch (Exception e) {
		}
		return new AddGroupResponse(Boolean.TRUE);
	}

}
